<?php
	require_once (dirname(__FILE__)."/../config/Config.inc");
	
	require_once ROOTDIR . 'source/third/aliyun_oss/samples/Common.php';
	
	use OSS\OssClient;
	use OSS\Core\OssException;
	
	$bucket = Common::getBucketName();
	$ossClient = Common::getOssClient();
	if (!is_null($ossClient))
	{
		$typeArr = array("jpg", "png", "gif","jpeg",'mp4','mp3');//允许上传文件格式
		
		$name = $_FILES['file']['name'];
	    $size = $_FILES['file']['size'];
	    $name_tmp = $_FILES['file']['tmp_name'];
	    if (empty($name))
	    {
	       echoJSON(array("code"=>'1',"msg"=>"您还未选择图片","error"=>"您还未选择图片"));
	    }
	    $type = strtolower(substr(strrchr($name, '.'), 1)); //获取文件类型
	    
	    if (!in_array($type, $typeArr))
	    {
	       echoJSON(array("code"=>'1',"msg"=>"文件格式不正确！","error"=>"文件格式不正确！"));
	    }
		
		$pic_name = time() . rand(10000, 99999) . "." . $type;//图片名称
		
		$ossClient->uploadFile($bucket, $pic_name, $_FILES['file']['tmp_name']);
		//Common::println("b.file is created");
		echoJSON(array("code"=>'0',"error"=>"0","data"=>array('src'=>OSS_URL.$pic_name,'title'=>$name),"pic"=>OSS_URL.$pic_name,"name"=>$pic_name,"size"=>$size));
	}
	else
	{
		
	}
	